<?php

if (!defined('BASEPATH'))
	exit('No Direct Access Allowed !');

/**
*  
*/
class diagnosa extends CI_Controller
{
	
	function __construct()
	{

		parent::__construct();
		$this->load->model('m_diagnosa');
		$this->load->model('m_penyakit');

	}

	function index(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$this->load->view('global/header');
			$this->load->view('diagnosis/index');
			$this->load->view('global/footer');
		}
	}

	function sapi(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$data['hewan']='Sapi';
			$data['data'] = $this->m_diagnosa->ambil('1');
			$data['param'] = 'sapi';
			$this->load->view('global/header');
			$this->load->view('diagnosis/data', $data);
			$this->load->view('global/footer');
		}

	}
	function kambing(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$data['hewan']='Kambing';
			$data['data'] = $this->m_diagnosa->ambil('2');
			$data['param'] = 'kambing';
			$this->load->view('global/header');
			$this->load->view('diagnosis/data', $data);
			$this->load->view('global/footer');
		}
		
	}

	function domba(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$data['hewan']='Domba';
			$data['data'] = $this->m_diagnosa->ambil('3');
			$data['param'] = 'domba';
			$this->load->view('global/header');
			$this->load->view('diagnosis/data', $data);
			$this->load->view('global/footer');
		}
		
	}

	function klasifikasi(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$data['penyakit'] = $this->m_penyakit->ambil();
			$data['gejala'] = $this->m_penyakit->ambilsemuagejala();
			$this->load->view('global/header');
			$this->load->view('diagnosis/klasifikasi', $data);
			$this->load->view('diagnosis/footer');
		}
	}

	function hapus($jenis, $id_penyakit){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$this->m_diagnosa->hapus($jenis, $id_penyakit);
			redirect('diagnosa'.'/'.$jenis);

		}
	}




	function hapus_gejala($jenis, $id_penyakit ,$id_bobot_gejala){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
			$this->m_diagnosa->hapus_gejala($jenis, $id_bobot_gejala);
			redirect('diagnosa'.'/'.$jenis.'/'.$id_penyakit);

		}
	}
	function get_gejala_json(){
		$kd_gejala = $this->input->post('kd_gejala');
		$gejala = $this->m_diagnosa->gejala_by_kd($kd_gejala);
		$this->output->set_content_type('application/json');
		$this->output->set_output(json_encode($gejala,JSON_FORCE_OBJECT));
	}

	function get_penyakit_json(){
		$kd_penyakit = $this->input->post('kd_penyakit');
		$penyakit = $this->m_diagnosa->penyakit_by_kd($kd_penyakit);
		$this->output->set_content_type('application/json');
		$this->output->set_output(json_encode($penyakit,JSON_FORCE_OBJECT));
	}

	function simpan_diagnosa(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else { 
			$this->form_validation->set_rules('kd_penyakit', 'Kode Penyakit', 'trim|required');
			$this->form_validation->set_rules('kd_gejala', 'Kode Gejala', 'trim|required');
			if ($this->input->post('submit')) {
				if ($this->form_validation->run() == FALSE) {
					$data['kd_penyakit'] = $this->input->post('kd_penyakit');
					$data['id_penyakit'] = $this->input->post('id_penyakit');
					$data['kd_gejala'] = $this->input->post('kd_gejala');
					$data['id_gejala'] = $this->input->post('id_gejala');
					$this->load->view('global/header');
					$this->load->view('diagnosis/klasifikasi', $data);
					$this->load->view('diagnosis/footer');
				}else{
					$this->m_diagnosa->insertbobot();
					redirect('diagnosa/klasifikasi');
				}
			}
		}

	}
}